/*
	A computer quiz by Ben
	C++ Version
*/

#include <iostream>
using namespace std;

int const QUESTION_MAX = 10;

//The quiz questions and answers.
char *questions[10][5] = {
	{ "What is the smallest unit in the computer.", "Block", "Byte", "Bit", "C" },
	{ "The most widely used computer device is.", "Solid state disks", "Mouse", "Hard Disk", "C" },
	{ "WWW stands for.", "Wan Wide World.", "World Wide Web", "Wide Wan Web", "B" },
	{ "What is used to view web pages.", "Internet", "Web Browser", "Page Browser", "B" },
	{ "Which one is a word processer.", "Notepad.", "MS-Excel", "MS-Word", "C" },
	{ "How many bits are in one byte.", "1", "8", "4", "B" },
	{ "ISP stands for.", "International Service Provide", "Internet Service Printer", "Internet Service Provider", "C" },
	{ "How many bytes are in 2040 bits.", "255", "1024", "100", "A" },
	{ "Every number system has a base, which is called", "Index", "Radix", "Subscript", "B" },
	{ "A device that converts digital signals to analog signals is", "Packet", "Modem", "Block", "B" }
};

char select_question = '\0';
char correct_answer = '\0';
int score = 0;

void showOptions(int qIndex){
	//Show available answers user can choose.
	std::cout << "(A) " << questions[qIndex][1] << endl;
	std::cout << "(B) " << questions[qIndex][2] << endl;
	std::cout << "(C) " << questions[qIndex][3] << endl;
}

double compute_final(){
	//Compute the final score
	return (100 * score) / QUESTION_MAX;
}

void check_answer(int qIndex){
	//Get correct answer.
	correct_answer = questions[qIndex][4][0];
	//Check for correct answer
	if (correct_answer == select_question){
		//Add 1 to the score count.
		score++;
	}
}

int main(){
	int i = 0;
	//Load all the questions.
	while (i < QUESTION_MAX){
		//Display question
		std::cout << questions[i][0] << endl;
		//Display answer options.
		showOptions(i);
		//Read in answer;
		std::cout << endl;
		std::cout << "Enter choice: ";
		//Load users answer
		std::cin >> select_question;
		//Convert to uppercase;
		select_question = toupper(select_question);
		//Check the answer.
		check_answer(i);
		std::cout << endl;
		//INC question.
		i++;
	}

	//Write out final score.
	std::cout << "The test has finished." << endl;
	std::cout << "You got " << score << " questions right out of " << QUESTION_MAX << endl;
	std::cout << "You scored " << compute_final() << "%" << endl;
	system("pause");

	return 0;
}